package ygw.study.tool;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.client.RestTemplate;

/**
 * <p>
 * xxxxx
 * </p>
 * <p>
 * Copyright:2023.All rights reserved.
 * </p>
 * <p>
 * Company:Zsoft
 * </p>
 * <p>
 * CreateDate:2023-02-15 16:54
 * </p>
 *
 * @author YuGongWen
 * @history Mender:YuGongWen；Date:2023-02-15 16:54；
 */
public class HolidayMain {
    
    public static String getDay() {
        /*
         * 互联网节假日api接口，公安网需要主动导入配置
         * www.mxnzp.com
         * ignoreHoliday: 是否忽略节假日，仅仅获取万年历，默认值false
         */


        /**
         访问 http://blog.mxnzp.com/?p=59 获取 app_id、app_secret
         
         */
        RestTemplate restTemplate = new RestTemplate();
        // String url = "https://www.mxnzp.com/api/holiday/list/year/2022" + "?ignoreHoliday=false&app_id=登录官网创建&app_secret=登录官网创建";
        String url = "https://www.mxnzp.com/api/holiday/list/year/2022"  + "?ignoreHoliday=false&app_id=ba1oodhnjgvdpnus&app_secret=eUMvbnMxY1FCbDZiOUpGY0tUcjdtdz09";
        HolidayResult result = restTemplate.getForObject(url, HolidayResult.class);

        if(result.getCode() != null && result.getCode() == 1){
            //成功: code: 状态码 1.返回成功 0.返回失败
            if(!CollectionUtils.isEmpty(result.getData())){
                for (HolidayData data : result.getData()) {
                    System.out.println("月份: "+data.getMonth());
                    for (Holiday day : data.getDays()) {
                        System.out.println(day.getDate()+"\t"+day.getType()+"\t"+day.getTypeDes());
                    }
                    System.out.println("\n");
                }
            }
        }else{
            //失败
        }

        return result.getMsg();
    }


    public static void main(String[] args) {
        String day = getDay();
        System.out.println("（代码标识号： GZ-ZHBS-5876223785892743）day = " + day);
        
        
    }

}